
let fs = require('fs')
let path = require('path')

function copy(src,dist){

    if(!fs.existsSync(src))return;
    if(!fs.existsSync(dist)){
        fs.mkdirSync(dist)
    }
    if(fs.statSync(src).isDirectory()){
        
        let arr = fs.readdirSync(src).map(item =>{
            return {
                copyName:item,
                copyText:path.join(src,item),
                copyType:fs.statSync(path.join(src,item)).isFile()
            }
        })
        arr.forEach(item =>{
            let {copyName,copyText,copyType} = item;
            if(copyType){
                fs.writeFileSync(path.join(dist,copyName),fs.readFileSync(copyText))
            }else{
                fs.mkdirSync(path.join(dist,copyName))
            }
             
        })
    }

}

module.exports = {copy}